class Solution(object):
    def characterReplacement(self, s, k):
        """
        :type s: str
        :type k: int
        :rtype: int
        """
        n = len(s)
        max_len = 0
        for i in range(26):
            t = chr(ord('A') + i)
            left = 0
            right = 0
            count = 0
            while right < n:
                if s[right] != t:
                    count += 1
                    if count > k:
                        max_len = max(max_len, right - left)
                        while left <= right:
                            if s[left] != t:
                                left += 1
                                break
                            left += 1
                        count -= 1
                right += 1
            max_len = max(max_len, right - left)
        return max_len



data = Solution()
s = "ABAB"
k = 2
print(data.characterReplacement(s, k))
